package dev.ece.suit.multisample;

import java.io.InputStream;

import org.lwjgl.opengl.GL20;

import dev.ece.core.shader.Shader;
import dev.ece.core.texture.Texture;

public class MultiSampleShader extends Shader {

	private int textureHandler;
	
	private int multiSampleHandler;
	
	public MultiSampleShader(InputStream vertexShaderInputStream,
			InputStream pixelShaderInputStream) {
		super(vertexShaderInputStream, pixelShaderInputStream);
	}
	
	@Override
	protected void onInitializeHandler(int program) {
		textureHandler = GL20.glGetUniformLocation(program, "baseTexture");
		multiSampleHandler = GL20.glGetUniformLocation(program, "ece_MultiSample");
	}

	@Override
	protected void onBindAttribLocations(int program) {
		GL20.glBindAttribLocation(program, 0, "vao_Vertex");
		GL20.glBindAttribLocation(program, 1, "vao_TexCoord");
	}
	
	public void glMultiSample(int multiSample) {
		GL20.glUniform1i(multiSampleHandler, multiSample);
	}
	
	public void glTexture(Texture texture) {
		GL20.glUniform1i(textureHandler, texture.bind(0));
	}

	public static MultiSampleShader createMultiSampleShader() {
		MultiSampleShader shader = new MultiSampleShader(
				MultiSampleShader.class.getClassLoader().getResourceAsStream("shaders/multisample.vert"),
				MultiSampleShader.class.getClassLoader().getResourceAsStream("shaders/multisample.frag"));
		return shader;
	}

	@Override
	public void clearup() {
		GL20.glDeleteShader(this.textureHandler);
		GL20.glDeleteShader(this.multiSampleHandler);
		super.clearup();
	}
	
}
